<?php
header("Content-Type: application/json");
include('../../include/functions.inc.php');

$strQuery ='SELECT  DISTINCT cllg_empresa.*
            FROM    cllg_empresa';
$arrEmpresas = $db->query_toArray($strQuery);

$strTMP = '[';
$intContador = 0;

foreach( $arrEmpresas as $arrTMP ) {
    
    $strTMP .= ($intContador == 0) ? "" : ",";
    $nit = getFieldValue($db, "cllg_empresa", $arrTMP["ID"], "EMPRESA_NIT");
    $nit = isset($nit[0]) ? $nit[0] : '';
    $dir = getFieldValue($db, "cllg_empresa", $arrTMP["ID"], "EMPRESA_DIR");
    $dir = isset($dir[0]) ? $dir[0] : '';
    $name = getFieldValue($db, "cllg_empresa", $arrTMP["ID"], "EMPRESA_NOMBRE_FACTU");
    $name = isset($name[0]) ? $name[0] : '';
    $strTMP .= json_encode(array(
        "ID" => $arrTMP["ID"],
        "NIT" => isset($nit["VALUE"]) ? $nit["VALUE"] : '-',
        "NOMBRE" => isset($name["VALUE"]) ? $name["VALUE"] : '-',
        "DIRECCION" => isset($dir["VALUE"]) ? $dir["VALUE"] : '-',
        "EMPRESA" => $arrTMP["NOMBRE"])
    );
    $intContador++;
    
}

print $strTMP . "]";
?>